/*
 * @Author: 
 * @Date: 2022-01-26 16:35:34
 * @LastEditors: lqj
 * @LastEditTime: 2022-02-10 14:34:43
 * @Description: 路由传参
 */
import React, { useState, useEffect } from 'react';
import axios from 'axios'
import { Button } from 'antd';
import {
  useLocation,
  // useRouteMatch, useParams, useHistory
} from 'react-router-dom'

export default function GetData(props) {
  const [name, setName] = useState('jack')
  useEffect(() => {
    setName('lum')
  }, [])
  let getInitData = () => {
    axios.get('http://localhost:3000/api1/students')
      .then(res => console.log(res))
      .catch()
  }
  const location = useLocation()
  const label = location.query ? location.query.label : 0
  const title = location.state ? location.state.title : 0
  // console.log(props)
  return (
    <div>
      <div>
        <p>{name}</p>
        <span>{label || 0} - {title || 0}</span>
      </div>
      <Button onClick={getInitData}>点击获取数据</Button>
    </div>
  );
}

